package engine.display.newAttack
{
	import engine.display.newAttack.vo.FightInfoVo;
	
	import flash.display.MovieClip;
	import flash.text.TextField;
	import flash.ui.Mouse;
	
	import newx.StageInfo;
	import newx.com.ResManager;
	import newx.com.config.StaticIni;

	public class AttackTipsLogic
	{
		private var _tipsUi 	: MovieClip;
		
		private var _nameTxt	: TextField;
		
		private var _lvTxt		: TextField;
		
		private var _skillTxt	: TextField;
		
		private var _hpLine	: MovieClip;
		
		private var _spLine	: MovieClip;
		
		private var _hpTxt		: TextField;
		
		private var _spTxt		: TextField;
		
		private var _hpWidth	: int;
		
		private var _spWidth	: int;
		
		
		private static	 var _self	:	AttackTipsLogic;
		
		public static function getInstance():AttackTipsLogic
		{
			if ( _self == null )
			{
				_self = new AttackTipsLogic();
			}
			return _self;
		}
		
		public function AttackTipsLogic()
		{
			_tipsUi = ResManager.newResClass( "custSkin_2" ) as MovieClip;
			
			_nameTxt= _tipsUi.txt1;
			
			_lvTxt	= _tipsUi.txt2;
			
			_skillTxt=_tipsUi.txt3;
	
			_hpLine	= _tipsUi.hpLine;
			
			_spLine = _tipsUi.spLine;
			
			_hpWidth= _hpLine.width;
			
			_spWidth= _spLine.width;
			
			_hpTxt	= _tipsUi.txt4;
			
			_spTxt	= _tipsUi.txt5;
			
			_tipsUi.mouseChildren = _tipsUi.mouseEnabled = _tipsUi.visible = false;
		}
		
		public function showTips( fightInfoVo : FightInfoVo ):void
		{
			_nameTxt.htmlText = fightInfoVo.name;
			
			_lvTxt.htmlText = fightInfoVo.lv+"级";
			
			_hpLine.width =	_hpWidth * Math.min( 1, ( fightInfoVo.hp / fightInfoVo.maxHp ) );
			
			_spLine.width =	_spWidth * Math.min( 1, ( fightInfoVo.mp / fightInfoVo.maxMp ) );
			
			_hpTxt.text = fightInfoVo.hp + "/" + fightInfoVo.maxHp;
			
			_spTxt.text = fightInfoVo.mp + "/" + fightInfoVo.maxMp;
			
			_skillTxt.htmlText = StaticIni.getSwfLangStr( fightInfoVo.skill );
			
			_tipsUi.visible = true;
			
			StageInfo.stage.addChild( _tipsUi );
			
			moveTo( StageInfo.stage.mouseX, StageInfo.stage.mouseY );
		}
		
		public function hideTips():void
		{
			_tipsUi.visible = false;
			
			if( _tipsUi.parent )
			{
				_tipsUi.parent.removeChild( _tipsUi );
			}
		}
		
		public function moveTo( x : int, y : int ):void
		{
			_tipsUi.x = x + 4;
			_tipsUi.y = y + 4;
		}
	}
}